﻿using GM_Shop.BLL;
using GM_Shop.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace GM_Shop.Controllers
{
    public class GMShopMethodController : Controller
    {
        [HttpPost]
        public ActionResult Announcement()
        {
            return Json(new Announcement().getAnnouncement());
        }

        [HttpPost]
        public ActionResult NewRelease()
        {
            return Json(new NewRelease().getNewRelease());
        }

        [HttpPost]
        public ActionResult CommodityType()
        {
            return Json(new CommodityType().getCommodityType());
        }

        [HttpPost]
        public ActionResult CommodityInfo()
        {
            return Json(new CommodityInfo().getCommodityInfo());
        }

        [HttpPost]
        public ActionResult CommodityInfoCount(string typeName, string count = null)
        {
            var date = new CommodityInfo().getCommodityInfoByCount(typeName, count);
            return Json(date);
        }

        [HttpPost]
        public ActionResult ShopingCar(int[] arr)
        {
            if (Session["UserId"] == null) return Json(new CJson(10, "请重新登录"));
            return Json(new ShopingCar().AddShopCar(arr, Convert.ToInt32(Session["UserId"])));
        }

        [HttpPost]
        public ActionResult ShoppingCart()
        {
            if (Session["UserId"] == null) return Json(new CJson(10, "请重新登录"));
            return Json(new ShoppingCart().getShoppingCart(Convert.ToInt32(Session["UserId"])));
        }

        [HttpPost]
        public ActionResult ProvinceList()
        {
            return Json(new Area().getProvinceList());
        }

        [HttpPost]
        public ActionResult CityList(string city)
        {
            return Json(new Area().getCityList(city));
        }

        [HttpPost]
        public ActionResult BuyGoods(string[] Info) {
            if (Session["UserId"] == null) return Json(new CJson(10, "请重新登录"));
            return Json(new UserReceiptPath().insertUserReceiptPath(Info, Convert.ToInt32(Session["UserId"])));
        }

        [HttpPost]
        public ActionResult DelShopCar(string ShopId) {
            if (!int.TryParse(ShopId, out int i)) return Json(new CJson(0, "删除失败"));
            return Json(new ShoppingCart().delShoppingCart(ShopId));
        }

    }
}